package com.tjetc.view.impl;

import com.tjetc.constant.CommonConstant;
import com.tjetc.exception.MessageException;
import com.tjetc.utils.DruidUtils;
import com.tjetc.utils.RedisUtils;
import com.tjetc.utils.ScannerUtils;
import com.tjetc.view.AdminPage;
import com.tjetc.view.MainPage;
import com.tjetc.view.UserPage;

/**
 * @Author: itda
 * @Date: 2024/5/9 13:06
 * @Description: MainViewImpl
 */
public class MainPageImpl implements MainPage {
    private AdminPage adminPage = new AdminPageImpl();
    private UserPage userPage = new UserPageImpl();

    @Override
    public void show() {
        while (true) {
            System.out.println("******************************");
            System.out.println("*-----欢迎进入酒店预约系统-----*");
            System.out.println("*---------1.管理员-----------*");
            System.out.println("*---------2. 用户 -----------*");
            System.out.println("*---------3. 退出 -----------*");
            System.out.println("*****************************");
            System.out.println("请选择:");
            switch (ScannerUtils.sc.nextInt()) {
                case 1 -> adminPage.show();
                case 2 -> userPage.show();
                case 3 -> {
                    System.out.println("欢迎下次光临!");
                    DruidUtils.close();
                    System.exit(0);
                }
                default -> {
                    try {
                        throw new MessageException(CommonConstant.COMMAND_ERROR);
                    } catch (MessageException e) {
                        System.out.println(e.getMessage());
                    }
                }
            }
        }
    }
}
